import React, { Component } from 'react';
import { DatePicker } from 'antd';
import moment from "moment";



class MonthPicker extends Component {
    state =  {
        isopen: false,
        time: null
    };

    render() {
        const { isopen, time } = this.state;
        const {disabled,placeholder,defaultValue} = this.props;
        return (
            <div>
                <DatePicker
                    style={{width:438}}
                    value={time ? time : (defaultValue ? moment(defaultValue) : null)}
                    open={isopen}
                    mode="month"
                    placeholder={placeholder ? placeholder : "请选择月份..."}
                    format="YYYY-MM"
                    disabled={disabled ? disabled : false}
                    onOpenChange={(status) => {
                        if(status){
                            this.setState({isopen: true})
                        } else {
                            this.setState({isopen: false})
                        }
                    }}
                    onPanelChange={(v) => {
                        this.props.onChange(v);
                        this.setState({
                            time: v,
                            isopen: false
                        })
                    }}
                    onChange={() => {
                        this.setState({time: null})
                    }}
                />
            </div>
        );
    }
}

export default MonthPicker;
